﻿using System;
using System.Collections.Generic;

namespace OpenQuant.Quik
{
    /// <summary>
    /// Уникальный ключ для инструментов Quik
    /// </summary>
    public class SecurityKey: IEqualityComparer<SecurityKey>
    {
        /// <summary>
        /// Код инструмента
        /// </summary>
        public string Code { get; set; }
        /// <summary>
        /// Класс инструмента
        /// </summary>
        public string Board { get; set; }

        public bool Equals(SecurityKey securityKeyX, SecurityKey securityKeyY)
        {
            if (securityKeyX == null) throw new ArgumentNullException("securityKeyX");
            if (securityKeyY == null) throw new ArgumentNullException("securityKeyY");

            return GetHashCode(securityKeyX) == GetHashCode(securityKeyY);
        }

        public int GetHashCode(SecurityKey securityKey)
        {
            if (securityKey == null) throw new ArgumentNullException("securityKey");

            return securityKey.Board.GetHashCode() ^ securityKey.Code.GetHashCode();
        }

        public override string ToString()
        {
            return string.Format("Code={0};Board={1}", Code, Board);
        }
    }
}
